package com.insuremonitor.system.service.impl;

import com.insuremonitor.system.domain.*;
import com.insuremonitor.system.mapper.*;
import com.insuremonitor.system.service.IFrontWarrantyReportInsureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 保险投保信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-11-22
 */
@Service
public class FrontWarrantyreportInsureServiceImpl implements IFrontWarrantyReportInsureService
{
    @Autowired
    private FrontWarrantyInsureMapper frontWarrantyInsureMapper;

    @Autowired
    private FrontInsureRateExtendMapper frontInsureRateExtendMapper ;

    @Autowired
    private FrontInsureRateGoodsMapper frontInsureRateGoodsMapper;

    @Autowired
    private FrontInsureRateKindMapper frontInsureRateKindMapper;




    /**
     * 查询保险投保信息列表
     * 
     * @param frontWarrantyInsure 保险投保信息
     * @return 保险投保信息
     */
    @Override
    public List<FrontWarrantyInsure> selectList(FrontWarrantyInsure frontWarrantyInsure)
    {
        frontWarrantyInsure.setStatus("1");
        frontWarrantyInsure.setOrderStatus("3"); //订单成功
        return frontWarrantyInsureMapper.selectFrontWarrantyInsureList(frontWarrantyInsure);
    }

    /**
     * 查询保险投保信息
     *
     * @param warrantyId 保险投保信息主键
     * @return 保险投保信息
     */
    @Override
    public FrontWarrantyInsure selectFrontWarrantyInsureByWarrantyId(Long warrantyId)
    {
        FrontWarrantyInsure frontWarrantyInsure = frontWarrantyInsureMapper.selectFrontWarrantyInsureByWarrantyId(warrantyId);
        if(frontWarrantyInsure!=null){

            if(frontWarrantyInsure.getInsureExtendIds()!=null ){
                String[] InsureExtendIds = frontWarrantyInsure.getInsureExtendIds().split(",");
                if(InsureExtendIds.length>0){
                    List<FrontInsureRateExtend> frontInsureRateExtendLis=new ArrayList<FrontInsureRateExtend>();
                    for(String extendId:InsureExtendIds){
                        FrontInsureRateExtend insureRateExtend = frontInsureRateExtendMapper.selectFrontInsureRateExtendByInsureExtendId(Long.valueOf(extendId));
                        frontInsureRateExtendLis.add(insureRateExtend);
                    }
                    frontWarrantyInsure.setInsureRateExtends(frontInsureRateExtendLis);
                }
            }


            if(frontWarrantyInsure.getInsureKindId()!=null ){
                FrontInsureRateKind insureRateKind = frontInsureRateKindMapper.selectFrontInsureRateKindByInsureKindId(frontWarrantyInsure.getInsureKindId());
                if(insureRateKind!=null){
                    FrontInsureRateGoods frontInsureRateGoods = frontInsureRateGoodsMapper.selectFrontInsureRateGoodsByInsureGoodsId(frontWarrantyInsure.getInsureGoodsId());
                    insureRateKind.setInsureRateGoods(frontInsureRateGoods);
                }
                frontWarrantyInsure.setInsureRateKind(insureRateKind);
            }
        }
        return frontWarrantyInsure;
    }



}
